<?php
class Section extends Ecore_Db {
	var $cache;
	var $clear;
	public function __construct()
	{
		$this->cache = new Ecore_Cache();
		$this->clear = $this->cache->clear;
	}	
	public function get($intSectionId) {
		try {
			$this->prepare('call asections_get(?)');
			$this->bindParam(1, $intSectionId, PDO::PARAM_INT, 11);
			$arrResult 	= $this->fetchAll();					
			return isset($arrResult[0]) ? $arrResult[0] : null;
		} catch(Exeception $e) {
			Ecore_Function::logDb('Section::get - ' .$e->getMessage());
		}
	}
	public function getAll($intOff, $intLimit, &$intTotal=0) {
		try {
			$this->prepare('call asections_getall_a(?,?)');
			$this->bindParam(1, $intOff, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intLimit, PDO::PARAM_INT, 4);
			$arrResult 	= $this->fetchAll();		
			$intTotal	= isset($arrResult[0]['foundRows']) ? $arrResult[0]['foundRows'] : 0;	
			return isset($arrResult) ? $arrResult : null;
		} catch(Exeception $e) {
			Ecore_Function::logDb('Section::getAll - ' .$e->getMessage());
		}
	}
	public function add($strCode, $strName, $intPermA) {
		try {
			$this->prepare('call asections_add(?,?,?)');
			$this->bindParam(1, $strCode, 	PDO::PARAM_STR, 50);
			$this->bindParam(2, $strName, 	PDO::PARAM_STR, 150);
			$this->bindParam(3, $intPermA, 	PDO::PARAM_INT, 4);
			$arrResult 	= $this->fetchAll();					
			return isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : -1;
		} catch(Exeception $e) {
			Ecore_Function::logDb('Section::add - ' .$e->getMessage());	
		}
	}	
	public function update($intSectionId, $strName, $intEnabled, $intPermA) {
		try {
			$this->prepare('call asections_update(?,?,?,?)');
			$this->bindParam(1, $intSectionId, 	PDO::PARAM_INT, 11);
			$this->bindParam(2, $strName, 		PDO::PARAM_STR, 150);
			$this->bindParam(3, $intEnabled, 	PDO::PARAM_INT, 4);
			$this->bindParam(4, $intPermA, 		PDO::PARAM_INT, 4);
			$this->execute();
		} catch(Exeception $e) {
			Ecore_Function::logDb('Section::update - ' .$e->getMessage());	
		}
	}
}
